﻿namespace EnergyGeneratorSimVisualizer.Views
{
    using System.Windows;
    using System.Windows.Controls;

    /// <summary>
    /// Interaction logic for ChartView.xaml
    /// </summary>
    public partial class ChartView : UserControl
    {
        public static readonly DependencyProperty TitleProperty = DependencyProperty.Register(
            "Title",
            typeof(object),
            typeof(ChartView),
            new UIPropertyMetadata(string.Empty));

        public static readonly DependencyProperty BindingValueProperty = DependencyProperty.Register(
            "BindingValue",
            typeof(string),
            typeof(ChartView),
            new UIPropertyMetadata(string.Empty, OnBindingValueChanged));

        /// <summary>
        /// Initializes a new instance of the <see cref="ChartView"/> class.
        /// </summary>
        public ChartView()
        {
            this.InitializeComponent();
        }

        public object Title
        {
            get { return (object)GetValue(TitleProperty); }
            set { SetValue(TitleProperty, value); }
        }

        public string BindingValue
        {
            get { return (string)GetValue(BindingValueProperty); }
            set { SetValue(BindingValueProperty, value); }
        }

        private static void OnBindingValueChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            var me = sender as ChartView;

            if (me == null)
            {
                return;
            }

            me.ValueBinding.Path = new PropertyPath((string)e.NewValue);
        }
    }
}
